package com.dyl.oss.controller;

import com.dyl.common.core.RR;
import com.dyl.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(description="文件管理")
@RestController
@RequestMapping("/uploadFile")
@CrossOrigin
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation(value = "上传文件(OSS存储)")
    @PostMapping("oss")
    public RR oss(@RequestBody MultipartFile file){
        String url = fileService.uploadFileOSS(file);
        return RR.ok().data("url",url);
    }

    @ApiOperation(value = "上传文件(本地存储)")
    @PostMapping("thisLocality")
    public RR thisLocality(@RequestBody MultipartFile file){
        String url = fileService.uploadThisLocality(file);
        return RR.ok().data("url",url);
    }

    @ApiOperation(value = "本地文件预览")
    @PostMapping("thisLocalityPreview")
    public void thisLocalityPreview(@RequestBody MultipartFile file){
      fileService.thisLocalityPreview();
    }

}
